package me.chan.time;

import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.Month;
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Locale;
import java.util.TimeZone;

public class DateTimeFormatterDemo {

	public static void main(String[] args) {
		DateTimeFormatter formatter = DateTimeFormatter.ofPattern("d. MMMM yyyy", Locale.FRENCH);
		LocalDate date1 = LocalDate.of(2012, 06, 26);
		String formattedDate = date1.format(formatter);		
		System.out.println(formattedDate);		//26. juin 2012
		
		ZoneId zoneId = TimeZone.getDefault().toZoneId();
		System.out.println(zoneId);
		
		ZoneId  chicagoZone = ZoneId.of("America/Chicago");
		LocalDate date = LocalDate.of(2014, 3, 28);
		ZonedDateTime zdt1 = date.atStartOfDay(chicagoZone);
		System.out.println(zdt1);
		
		//为时间点增加时区
		LocalDateTime dateTime = LocalDateTime.of(2014, Month.MARCH, 18, 13, 45);
		ZonedDateTime zdt2 = dateTime.atZone(chicagoZone);
		System.out.println(dateTime + "\n" + zdt2);
		
		Instant instant = Instant.now();
		ZonedDateTime zdt3 = instant.atZone(chicagoZone);
		System.out.println(zdt3);
		
		//通过zoneId将LocalDateTime 转换为Instant
		//LocalDateTime localDateTime = LocalDateTime.of(2014, Month.MARCH, 18, 13, 45);
		//Instant instantFromLocalDateTime = localDateTime.toInstant(ZoneOffset.of("+6"));
		//System.out.println(instantFromLocalDateTime);
		LocalDate localDate = LocalDate.now();
		System.out.println(localDate);
		
		Instant now = Instant.now();
		LocalDateTime timeFromInstant = LocalDateTime.ofInstant(now, ZoneId.of("Asia/Shanghai"));
		System.out.println(timeFromInstant);
	}

}
